package juc.mythread.communication;


class Tests3Await {

    // 定义锁对象
    private final Object locker = new Object();

    void testThreadMXBean() throws InterruptedException {
        Thread t1 = new Thread(() -> {
            try {
                System.out.println("wait开始");
                synchronized (locker) {
                    locker.wait();
                }
                System.out.println("wait结束");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        t1.start();

        // 保证 t1 先启动，wait() 先执行
        Thread.sleep(1000);

        Thread t2 = new Thread(() -> {
            synchronized (locker) {
                System.out.println("notify开始");
                locker.notifyAll();
                System.out.println("notify结束");

            }
        });
        t2.start();

        // 等待t2执行完成，避免主线程提前退出
        t2.join();
    }


}

